<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>

<!DOCTYPE>
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
	<meta name="viewport"
		  content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="format-detection" content="telephone=no"/>
	<title>用户支付</title>
	<script type="text/javascript" src="${basePath}resources/js/wechat/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<script type="text/javascript" src="${basePath}resources/js/wechat/js/common.js"></script>
	<script type="text/javascript" src="${basePath}resources/js/fontset.js"></script>
	<link type="text/css" rel="stylesheet" href="${basePath}resources/css/pay.css">
	<link type="text/css" rel="stylesheet" href="${basePath}resources/css/common.css">

	<style>
		.zf_length {
			width: 21rem;
			overflow: hidden;
			background: #f7f7f7;
			margin: 0 auto;
		}

		.zf_length ul li {
			width: 6rem;
			height: 6rem;
			float: left;
			margin: 0.5rem;
			overflow: hidden;
			border: 1px solid #38adff;
			box-sizing: border-box;
			border-radius: 0.3rem;
			background: #fff;
		}

		.zf_length ul li a {
			display: block;
			text-align: center;
			line-height: 6rem;
			position: relative;
			font-size: 1rem;
			color: #38adff;
		}

		.zf_length ul li a:active{
			background-color: #38adff;
			color:#fff;
		}
	</style>
</head>
<body>
<div class="loading"></div>

<div class="page home_page">
	<div class="home_zhifuinner">
		<div class="zf_logo">
			<%--<p><img src="${basePath}resources/images/wechat/login_tx.png" alt=""></p>--%>
			<p><img src="${sysNotice.logourl}" alt=""></p>
		</div>
		<div class="zf_sbzt"><span>设备情况</span><i><span
				id="pay_bdonline"   ${status eq "true"?"":"style='color: #f00;'"} >${status eq "true"?"在线":"离线"}</span></i>
		</div>
		<div class="zf_yhm" ${disCode eq 1 ? "" : "style=\"display: none\""}><span>使用优惠码</span></div>
		<div class="zf_length">
			<ul>
				<c:forEach var="entry" items="${discounts}" varStatus="index">
					<li><a href="javascript:;"><span>${entry.money}</span>元${entry.coin}币</a></li>
					<input type="hidden" value="${entry.discountid }" id="discountid${index.index}"/>
				</c:forEach>
			</ul>
		</div>
	</div>
</div>
<%--<div class="tc_zhifuuser">游艺设备•智联物联</div>--%>
<div class="tc_zhifuuser">${sysNotice.buttomcontent}</div>

<!-- 使用优惠码提示 -->
<div class="tc_youhuimapop ty_pop">
	<div class="popbg"></div>
	<div class="youhuima_inner">
		<p>使用优惠码</p>
		<p><input type="text" id="input_disCode" placeholder="请输入优惠码"></p>
		<p>
			<a href="javascript:;">取消</a>
			<a href="javascript:void(0);" onclick="payUsingDisCode($('#input_disCode').val())">确定</a>
		</p>
	</div>
</div>

</body>
</html>
<script type="text/javascript">

	$(function () {
		$(".zf_length ul li").each(function(n){
			$(this).click(function(){
				if (!${status}) {
					alert('设备离线，无法支付!');
					return;
				}
				var signal = ${signal};
				if (signal < 15) {
					alert('信号不好,请稍后再试!');
					return;
				}
				prepay($("#discountid" + n).val());
			});
		});
	});

	function prepay(discountid){
		$.ajax({
			url: '${basePath}/pay/rm/prepay',
			type: "POST",
			data: {
				deviceid:'${deviceId}',
				openid:'${openid}',
				discountid:discountid
			},
			dataType: "json",
			cache: false,
			success: function(message) {
				if (message.message.type == "success") {
					alert(message.tokenId);
					window.location.href = 'http://test.rm-tech.com.cn/platform/jspay.html?token_id=' + message.tokenId;
				} else {
					alert(message.message.content);
				}
			}
		});
	}


	$(".zf_yhm").on("click", function () {
		if ($(".tc_youhuimapop").is(":hidden")) {
			$("#input_disCode").val("").focus();
			$(".tc_youhuimapop").css("display", "block");
		}
	})

	function payUsingDisCode(disCode) {
		if (!${status}) {
			alert('设备离线，无法支付!');
			return;
		}
		var signal = ${signal};
		if (signal < 15) {
			alert('信号不好,请稍后再试!');
			return;
		}

		$.ajax({
			url: '${basePath}/pay/payWithCoupon',
			type: "POST",
			data: {
				deviceId: '${deviceId}',
				disCode: disCode
			},
			cache: false,
			success: function (message) {
				if (message == "SUCCESS") {
					window.location.href = '${basePath}/pay/success';
				} else{
					window.location.href = '${basePath}/pay/fail';
				}
			}
		});
	}
</script>
